package tech.yangzhijie.basic.gui;

import javax.swing.*;
import java.util.concurrent.TimeUnit;

/**
 * @Author: 探险家劫
 * @Date: 2021/11/24 13:09
 */
public class HelloSwing {
    public static void main(String[] args) throws InterruptedException {
        //helloSwing();
        //helloLabel();
        helloLabel2();
    }

    public static void helloSwing(){
        JFrame jFrame = new JFrame("Hello World");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setSize(300,100);
        jFrame.setVisible(true);
    }

    public static void helloLabel() throws InterruptedException {
        JFrame jFrame = new JFrame("Hello Swing");
        JLabel jLabel = new JLabel("A label");
        jFrame.add(jLabel);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setSize(300,100);
        jFrame.setVisible(true);
        TimeUnit.SECONDS.sleep(1);
        jLabel.setText("我的第一个Label");
    }

    public static void helloLabel2() throws InterruptedException {
        JFrame jFrame = new JFrame("Hello Swing");
        JLabel jLabel = new JLabel("A label");
        jFrame.add(jLabel);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setSize(300,100);
        jFrame.setVisible(true);
        TimeUnit.SECONDS.sleep(1);
        SwingUtilities.invokeLater(()->{
            jLabel.setText("我的第二个label");
        });
    }
}
